package world;

import java.util.HashMap;
import java.util.Map;

import math.EulerAngles;
import math.MatrixStack;
import math.Vector3f;
import world.map.ChunkProvider;
import world.map.ChunkProviderFlat;

public class World {
	public final static float CHUNK_SIZE = Chunk.SIZE;
	public MatrixStack matixStack = new MatrixStack();

	private Map<Integer, Chunk> chunks = new HashMap<Integer, Chunk>();
	private Camera camera;
	private ChunkProvider chunkProvider;

	public World() {
		this.chunkProvider = new ChunkProviderFlat(this);
	}

	public void load() {
		Vector3f pos = camera.getPosition();
		chunkProvider.loadChunks(pos.x, pos.y, pos.z);
	}

	public void render() {
		for (Chunk r : chunks.values()) {
			r.render();
		}
	}

	public boolean solidAt(float x, float y, float z) {
		if (y >  Chunk.SIZE) {
			return false;
		}

		chunkProvider.loadChunks(x, y, z);
		return chunkProvider.findBlock(x, y, z) != null;
	}

	public void addCamera(Camera camera, Vector3f position, EulerAngles rotation) {
		this.camera = camera;
		camera.setWorld(this, position, rotation);
	}

	public Map<Integer, Chunk> getChunks() {
		return chunks;
	}
}
